#include "BangoEvent.h"

BangoEvent::BangoEvent()
{
    _eventPosted = false;
}

BangoEvent::BangoEvent(int eventId, int connectionType, QString operatorConnectionType,
                       QString eventName, QString eventValue, QString eventDetail, QString eventTime, QString eventLocalTime,
                       int errorLevel, QString errorId, QVector<BangoNameValuePair> eventParameters
                       )
{
    _eventId = eventId;
    _connectionType = connectionType;
    _operatorConnectionType = operatorConnectionType;
    _eventName = eventName;
    _eventValue = eventValue;
    _eventDetail = eventDetail;
    _eventTime = eventTime;
    _eventLocalTime = eventLocalTime;
    _errorId = errorId;
    _errorLevel = errorLevel;
    _eventParameters = eventParameters;
    _eventPosted = false;
}

BangoEvent::~BangoEvent()
{
    _eventParameters.clear();
}

 QVariantMap BangoEvent::GetEventDetails()
{
    QVariantMap eventDetails;

    QVariantList eventParameters;

    eventDetails.insert(BangoFieldNames::POST_EVENTID, _eventId);
    eventDetails.insert(BangoFieldNames::POST_EVENTTIME, _eventTime);
    eventDetails.insert(BangoFieldNames::POST_EVENTLOCALTIME, _eventLocalTime);
    eventDetails.insert(BangoFieldNames::POST_CONNECTIONTYPE, BangoStatic::ConnectionType(_connectionType));
    eventDetails.insert(BangoFieldNames::POST_OPERATORCONNECTIONTYPE, _operatorConnectionType);
    eventDetails.insert(BangoFieldNames::POST_EVENTNAME, _eventName);
    eventDetails.insert(BangoFieldNames::POST_EVENTDETAIL, _eventDetail);
    eventDetails.insert(BangoFieldNames::POST_EVENTVALUE, _eventValue);
    eventDetails.insert(BangoFieldNames::POST_ERRORID, _errorId);
    eventDetails.insert(BangoFieldNames::POST_ERRORLEVEL, _errorLevel);

    if (_eventParameters.size() > 0)
    {
        QVectorIterator<BangoNameValuePair> iter(_eventParameters);

        while (iter.hasNext())
        {
            eventParameters.append(((BangoNameValuePair)iter.next()).GetDetails());
        }
    }
    eventDetails.insert("EventParameters", eventParameters);
    return eventDetails;
}
